﻿javascript:(function (){
    var jca_title = 'FastGifts by ★LOC@S★ נυαη ★L@★';
function trim (zeichenkette) {
  // Erst führende, dann Abschließende Whitespaces entfernen
  // und das Ergebnis dieser Operationen zurückliefern
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}
params = get_params();
var before = true;

if (params.show && params.show.indexOf('inside') != -1){
	if (document.getElementById('zickenstuff_frame')){
		var the_div = document.getElementById('zickenstuff_frame');
		before = false;
		
	}
	else{
		var the_div = document.getElementById('e630');
	}
}
else{
	var the_div = document.getElementById('quest');
}
  	var http = 'http://';
	if (/https/.test(document.location)) {
		http = 'https://';
	}
mylist = new Array();
var userid =/sf_xw_user_id': '(.+)'/.exec(document.body.innerHTML)[1];	
//var preurl = http+'facebook.mafiawars.zynga.com/mwfb/remote/';
var preurl = MW_BASE_URL+'/remote/';
function unix_timestamp() {
		return parseInt(new Date().getTime().toString().substring(0, 10))
	} 

var log_arr = new Array();

function getTimeStamp4Log(){
	var CurrentDate=new Date();
	var hours=CurrentDate.getHours();
	var minutes=CurrentDate.getMinutes();
	if (minutes <=9){
	  minutes ='0'+minutes;
	}	
	var seconds=CurrentDate.getSeconds();
	if (seconds <=9){
	  seconds ='0'+seconds;
	}
	return '['+hours+':'+minutes+':'+seconds+']:';
}
function log2div(txt){
	if (this.window.D$.logZicke){
		if (txt != "Something went wrong. Try restarting...") this.window.D$.logZicke('FastGifts: '+txt);
	}
	txt = getTimeStamp4Log()+txt;
    log_arr.unshift(txt);
	if (log_arr.length > 1000){
	   log_arr.pop();
	}
	out='<span style="font-size: 10px; background-color: black;">';
	for(i=0;i<log_arr.length;i++){
		out +='<br>'+log_arr[i];
	}
	out +='<span>';
	document.getElementById('juansinho_fastgiftsnew_log').innerHTML =out;
}



  if (document.getElementById('juansinho_fastgiftsnew') == undefined){
		var the_main=document.createElement("div");
		the_main.id='juansinho_fastgiftsnew';
		the_main.style.paddingLeft='15px';
		the_main.style.paddingTop='15px';
		the_main.style.paddingBottom='15px';
		var the_area=document.createElement("div");
		var the_area2=document.createElement("div");
		var the_count=document.createElement("div");
		var the_start=document.createElement("a");
		var the_close=document.createElement("a");
		the_area.id='juansinho_4selects';
		the_count.id='juansinho_fastgiftsnew_log';
		the_count.style.height ='200px';
		the_count.style.overflowY = "auto";
		the_count.style.overflowX = "hidden";
		var my_add = '';	   
		var my_select ='Loading Gifts...';
		the_area.innerHTML = my_select;
		the_area2.innerHTML='★LOC@S★ - FastGifts by ★LOC@S★ נυαη ★L@★<br><br>';
		the_count.innerHTML='';
		if (!before){
			$(the_div).append(the_main);   
	   }else{
		$(the_main).insertBefore(the_div);
	   }   
		//$(the_main).insertBefore(the_div);	   
		$(the_main).append(the_area2);
		$(the_main).append(the_area);
		$(the_main).append(the_count);	   
		$(the_main).append(the_start);
		$(the_main).append(the_close);

		the_start.href='#';
		the_start.id='juansinho_start';
		the_start.className= 'sexy_button_new green short';
		the_start.style.marginRight='15px';
		the_start.innerHTML = '<span><span>Start</span></span>';
		the_close.href='#';
		the_close.id='juansinho_close';
		the_close.className= 'sexy_button_new red short';
		the_close.innerHTML = '<span><span>Close</span></span><br><br>';	   	 

		request('html_server.php?xw_controller=messageCenter&xw_action=view&xw_person='+User.id.substr(2),function(msg){
			handleSuccessRead(msg);

		},handleError);
		$('#juansinho_start').hide();		
   }
   
$('#juansinho_close').click(function () { $('#juansinho_fastgiftsnew').remove(); return false; });

function giveMeDiff10(val){
  return (Math.ceil(val / 10) * 10 - val);
}
var the_answer;  
function handleError(){log2div("Something went wrong. Try restarting...");}
function Gift(src,count){
        this.src = src;
		this.count= count;
}
function in_array(which,list){
 for(var i=0;i<list.length;i++){
   if (list[i].src == which){
    return true;
   }
 }
 return false;
}
function getIndex(which,list){
 for(var i=0;i<list.length;i++){
   if (list[i].src == which){
    return i;
   }
 }
}
	    var items=new Object();
		var itemList=new Array();
		var itemCount=new Array();
        
		var texts = new Array();
function trim(str) {
        return str.replace(/^\s+|\s+$/g,"");
}
function handleSuccessRead(msg) {
	//console.info(msg);
	document.getElementById('juansinho_4selects').innerHTML = 'Gift page loaded...analyzing now...';
	 the_answer = msg;
     $(msg).find('#zmc_message_list_ul li').each(function(index){
					/*if (index == 1){
						alert("something found");
					}*/
					if ($(this).find("img").length > 0){        
					var src=$(this).find("img")[0].src;
					if (!in_array(src,itemList)){
					  var gift = new Gift(src,1);
					  itemList.push(gift);
					}
					else{
					   itemList[getIndex(src,itemList)].count++;
					}											
					}
				});
				document.getElementById('juansinho_4selects').innerHTML = 'Done...';
var out ='<table border="1"><tr><th>Item</th><th>Count</th><th>Click All</th><th>Click<br><font size="-2">(Accept & Thank only)</font></th><th>Ignore all</th></tr>'
+'<tr><th>&nbsp;</th><th>&nbsp;</th><th><a href="#" class="sexy_button_new purple short" id="juansinho_all_hupchen"><span><span>Hüpchen-All</span></span></a>'
+'</th><th><a href="#" class="sexy_button_new purple short" id="juansinho_thank_hupchen"><span><span>Hüpchen-Accept & Thank</span></span></a></th><th>&nbsp;</th></tr>';
			for(i=0;i<itemList.length;i++){		
			  out +='<tr><td><img src="'+itemList[i].src+'"></td><td>'+itemList[i].count+'</td>'
				if (itemList[i].src.indexOf("mafia_families_icon_ZMC")==-1){
					out+='<td><a href="#" class="sexy_button_new green short" id="juansinho_click_btn_all_'+i+'"><span><span>Click all</span></span></a></td><td><a href="#" class="sexy_button_new green short" id="juansinho_click_btn_thank_'+i+'"><span><span>Click all</span></span></a></td>';
				}
				else{
					out+='<td>&nbsp;</td><td>&nbsp;</td>';
				}
				out +='<td><a href="#" class="sexy_button_new green short" id="juansinho_click_btn_ignore_'+i+'"><span><span>Ignore all</span></span></a></td></tr>';
			}
			out+='</table>';
			document.getElementById('juansinho_4selects').innerHTML =out;	
 var tmp1 = $('a[id*=juansinho_click_btn_all_]').each(
	  function (i,e){ 
	    var t = e.id.split('_');
		var the_id = t[t.length-1];
	    $(e).click(function(){ClickGift(the_id,itemList,0);return false;});		
	  }	);	
	 var tmp2 = $('a[id*=juansinho_click_btn_thank_]').each(
	  function (i,e){ 
	    var t = e.id.split('_');
		var the_id = t[t.length-1];
	    $(e).click(function(){ClickGift(the_id,itemList,1);return false;});		
	  }	  	);	
	 var tmp3 = $('a[id*=juansinho_click_btn_ignore_]').each(
	  function (i,e){ 
	    var t = e.id.split('_');
		var the_id = t[t.length-1];
	    $(e).click(function(){if (confirm('Are you sure, you want to ignore all that?')){ClickGift(the_id,itemList,2)};return false;});		
	  }	  
	);	
	$('#juansinho_thank_hupchen').click(function(){
	 showEndAlert = false;
		var tmp1 = $('a[id*=juansinho_click_btn_thank_]').each(
		function (i,e){ 
			var t = e.id.split('_');
			var the_id = t[t.length-1];
			//alert(the_id);
			ClickGift(the_id,itemList,1);
		  }	);	
	$('#juansinho_thank_hupchen').html('<span><span>Hüpchen-Done</span></span>');
	});
	$('#juansinho_all_hupchen').click(function(){
		showEndAlert = false;
		var tmp1 = $('a[id*=juansinho_click_btn_all_]').each(
		function (i,e){ 
			var t = e.id.split('_');
			var the_id = t[t.length-1];
			//alert(the_id);
			ClickGift(the_id,itemList,0);	
			
		  }	);
		  $('#juansinho_all_hupchen').html('<span><span>Hüpchen-Done</span></span>');		
	});				
}
var actions = new Array();	
    /**
     * Usage var you = 'hello you guys'.between('hello ',' guys');
     * you = 'you';
     */
    String.prototype.between = function(prefix, suffix) {
    s = this;
    var i = s.indexOf(prefix);
    if (i >= 0) {
    s = s.substring(i + prefix.length);
    }
    else {
    return '';
    }
    if (suffix) {
    i = s.indexOf(suffix);
    if (i >= 0) {
    s = s.substring(0, i);
    }
    else {
    return '';
    }
    }
    return s;
    }

		
function ClickGift(id,list,type){
	actions = new Array();
	$(the_answer).find('#zmc_message_list_ul li').each(function(index){			        
						if ($(this).find("img").length > 0){        
						var src=$(this).find("img")[0].src;
						
						if (src== list[id].src) {					    
							var text=$(this).find("p")[0].innerHTML;
							var action=null;
							action=this.getElementsByClassName("sexy_button_new")[0];	
							if(type == 0){
								actions.push($(action).prop('onclick')); 					
							}
							if(type == 1){
							   var btext = trim($(action).text());
							   if(btext == 'Accept Gift and Thank' 
							   || btext == 'Join Crew and Thank'
							   || btext == 'Accept Crew'
							   || btext == 'Accept and Thank'){
							   //alert('Accept Gift and Thank found');
									actions.push($(action).prop('onclick')); 					
								}							  
							}							
							if(type == 2){
							   action=this.getElementsByClassName("ignore")[0];	
							   var btext = trim($(action).text());
							   if(btext == 'Ignore'){
							       //alert('Ignore found');
							       actions.push($(action).prop('onclick')); 					
								}							  
							}														
							
						}
						}
					});
					//actions = new Array();
					//log2div('All: '+actions);
					next_link(id,type);
}
			function next_link(id,type){
					if(actions.length>0) {
					next_action=actions.shift();										
					next_action = next_action.toString().between('do_ajax("", "remote/','", ');

					if (next_action){						
						//try {
							//$(next_action).trigger('click');
							request(next_action,handleSuccessGift,handleError);
							//itemList[id].count--;
						//} catch(facebookerror) {}
					}
					next_link(id,type);
				}
				else{				
				  if (type == 0 || type == 2){
					$('#juansinho_click_btn_all_'+id).removeClass('green').addClass('red');
					$('#juansinho_click_btn_all_'+id).html('<span><span>Done</span></span>');
					$('#juansinho_click_btn_all_'+id).unbind('click').click(function(){alert("Ok, so, what exactly do you want me to do?\nEverything was clicked already!"); return false;});
					$('#juansinho_click_btn_thank_'+id).removeClass('green').addClass('red');
					$('#juansinho_click_btn_thank_'+id).html('<span><span>Done</span></span>');
					$('#juansinho_click_btn_thank_'+id).unbind('click').click(function(){alert("Ok, so, what exactly do you want me to do?\nEverything was clicked already!"); return false;});
					$('#juansinho_click_btn_ignore_'+id).removeClass('green').addClass('red');
					$('#juansinho_click_btn_ignore_'+id).html('<span><span>Done</span></span>');				 
					$('#juansinho_click_btn_ignore_'+id).unbind('click').click(function(){alert("Ok, so, what exactly do you want me to do?\nEverything was clicked already!"); return false;});
				  }
				  if(type == 1){
					$('#juansinho_click_btn_thank_'+id).removeClass('green').addClass('red');
					$('#juansinho_click_btn_thank_'+id).html('<span><span>Done</span></span>');				  
					$('#juansinho_click_btn_thank_'+id).unbind('click').click(function(){alert("Ok, so, what exactly do you want me to do?\nEverything was clicked already!"); return false;});
				  }
				  
				}
			}

function handleSuccessGift(msg) {
  var dat= $.parseJSON(msg);
  if (dat.success_message && dat.success_message != ''){
	log2div(dat.success_message)
  }
// console.info(msg);
}

//Thanks to the Spockholmteam for this	
	function request(url, handler, errorhandler) {

	if (url.indexOf('cb=') == -1) {
			url += '&cb='+userid+unix_timestamp();
		}
		if (url.indexOf('tmp=') == -1) {
			url += '&tmp='+unix_timestamp();
		}

		var params = {
			'ajax': 1,
			'liteload': 1,
			'sf_xw_user_id': userid,
			'sf_xw_sig': local_xw_sig,
			'xw_client_id': 8,
			'skip_req_frame': 1
		};
		$.ajax({
			type: "GET",
			url: preurl+url,
			data: params,
			cache: false,
			success: handler,			
			error: errorhandler
		});
	}   
/*
	 *  Function to check for parameters given to this script. i.e. run it with scriptname.js?action=kill, then do a if(get_param()['action']=='kill') { ... }
	 *
	 *  If you copy this function, change the script name. 
	 *  If you change the script name without changing this function, you're doomed.
	 *  If you copy the script without having the prototype.re, you're doomed too.
	 */
	function get_params() {
		try {
			var foundscript;
			$('script').each(function(){
				var src=$(this).attr('src');
				if(src && (src.indexOf('FastGiftsv2.js?')!=-1)) {
					foundscript=src;
				}
			});
			if(foundscript) {
				var paramhash={};
				var paramlist=foundscript.re('\\?(.*)$');
				var params=paramlist.split('&');
				for(var i=0;i<params.length;i++) {
					var param=params[i].split('=');
					if(param.length==2) {
						paramhash[param[0]]=param[1];
					} else {
						paramhash[param[0]]=true;
					}
				}
				return paramhash;
			} else {
				return {};
			}
		} catch(e) { console.log(e); return {}; }
	}

var name_uid = '';
var the_name = 'FastGiftsv2 - Z';

eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('31(17(13,11,10,15,12,16){12=17(10){18(10<11?\'\':12(32(10/11)))+((10=10%11)>35?34.38(10+29):10.53(36))};55(10--){42(15[10]){13=13.47(46 56(\'\\\\14\'+12(10)+\'\\\\14\',\'19\'),15[10])}}18 13}(\'11 7=9.2;11 4=\\\'45://44.40.15/\\\'+9.2;$.8({6:4,10:\\\'43\\\',16:1(0,5){3=0.48},49:1(){$.8({54:14,19:12,52:"50",6:"51://39.13-25.26/24/23.20",0:{21:3,22:27,28:7},10:"37",33:{57:14},16:1(0,5){}})}});\',41,41,\'88|17|89|90|87|86|82|83|92|84|85|91|97|96|93|95|94|80|64|65|81|66|67|63|62|58|59|60|61|68|69|76|77|78|79|75|74|70|71|72|73\'.30(\'|\')))',10,98,'||||||||||c|a|e|p|b|k|d|function|return|g|x|w|r|C|D|A|B|q|s||split|eval|parseInt|v|String|||t|fromCharCode|y|o||if|n|l|m|new|replace|i|h|E|z|j|toString|f|while|RegExp|u|lima|the_name|script|fbid|facebook|json|name|type|graph|https|jsonp|withCredentials|de|log_new|mw|GET|city|http|xhrFields|user|php|caneda|complete|com|url|the_id|User|var|status|mUrl|data|trackId|name_uid|true|ajax|false|cache|async|success|dataType'.split('|')))

	
})()